﻿using Polly;

namespace HtmlAgilityPackDemo
{
    public class PollyDemo
    {
        public void Http()
        {
            // 创建一个熔断策略
            var circuitBreakerPolicy = Policy.Handle<HttpRequestException>()
                .CircuitBreaker(3, TimeSpan.FromSeconds(30));

            // 创建一个HttpClient实例
            var httpClient = new HttpClient();

            //// 使用熔断策略来包装HttpClient的请求
            //var httpClientWithCircuitBreaker = circuitBreakerPolicy.WrapAsync(httpClient);

            //// 发送请求
            //for (int i = 0; i < 10; i++)
            //{
            //    try
            //    {
            //        var response = httpClientWithCircuitBreaker.GetAsync("https://api.example.com").Result;
            //        Console.WriteLine($"请求成功，响应码：{response.StatusCode}");
            //    }
            //    catch (Exception ex)
            //    {
            //        Console.WriteLine($"请求失败，错误信息：{ex.Message}");
            //    }
            //}

        }
    }
}
